{% extends "layout.html" %}

{% block content %}
<div class="container-fluid">
    <ol class="breadcrumb">
        <li><a href="/">后台管理</a></li>
        <li><a href="javascript:void(0);" onclick="$('#menu-settings').trigger('click');">权限管理</a></li>
        <li class="active">角色管理</li>
    </ol>

    {# 表单 #}
    <form class="form-horizontal" method="post" action="">
        {{ form.csrf_token }}
        <p></p>
        <div class="form-group{% if form.role_id.errors %} has-error{% endif %}">
            {{ form.role_id.label(class="col-sm-2 control-label") }}
            <div class="col-sm-10">
                {{ form.role_id(class="form-control", placeholder="管理角色", data_width="fit", data_header="选择角色") }}
                {% for error in form.role_id.errors %}
                    <span class="help-block">{{ error }}</span>
                {% endfor %}
            </div>
        </div>
        <div class="form-group{% if form.module.errors %} has-error{% endif %}">
            {{ form.module.label(class="col-sm-2 control-label") }}
            <div class="col-sm-10">
                {{ form.module(class="form-control", placeholder="权限模块", maxlength="256") }}
                {% for error in form.module.errors %}
                    <span class="help-block">{{ error }}</span>
                {% endfor %}
                <span class="help-block">模块名称：会员,订单,留言,系统,权限,统计(半角逗号分隔)</span>
            </div>
        </div>
        <div class="form-group{% if form.note.errors %} has-error{% endif %}">
            {{ form.note.label(class="col-sm-2 control-label") }}
            <div class="col-sm-10">
                {{ form.note(class="form-control", placeholder="权限备注", maxlength="256") }}
                {% for error in form.note.errors %}
                    <span class="help-block">{{ error }}</span>
                {% endfor %}
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-success btn-load" data-loading-text="保存中">保存</button>
                <button type="reset" class="btn btn-default">重新填写</button>
            </div>
        </div>
    </form>

</div>

{% endblock %}

{% block extra_js %}
<script>
    // 初始化赋值
    var role_id = $('#role_id');
    role_id.selectpicker('val', '{{ form.role_id.data }}');
    // 处理选项修改
    role_id.on('changed.bs.select', function (event, clickedIndex, newValue, oldValue) {
        // console.log($('#role_id').val());
        window.location.href = '{{ url_for('admin.role') }}' + '?role_id=' + $('#role_id').val();
        // console.log(event);
        // console.log(clickedIndex);
        // console.log(newValue);
        // console.log(oldValue);
    });
</script>
{% endblock %}

